package com.lzx.guanchajava.adapter.newsListAdapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.library.baseAdapters.BR
import androidx.recyclerview.widget.RecyclerView
import com.lzx.guanchajava.R
import com.lzx.guanchajava.adapter.CommonListHolder
import com.lzx.guanchajava.pojo.TAG
import com.lzx.guanchajava.pojo.bean.newsList.News
import com.lzx.guanchajava.util.App
import com.lzx.guanchajava.util.ImageUtils
import com.lzx.guanchajava.util.JumpUtil
import com.lzx.guanchajava.view.activity.NewsActivity
import com.lzx.guanchajava.view.activity.PostActivity
import com.lzx.guanchajava.view.activity.TagsActivity
import com.lzx.guanchajava.view.widget.UrlImageView

abstract class BaseNewsType : INewsType {
    @LayoutRes abstract fun layoutId(): Int

    abstract fun dataType(): Array<Int>

    override fun isForViewType(news: News): Boolean {
        return news.show_type in dataType()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = CommonListHolder(
            DataBindingUtil.inflate(
                    LayoutInflater.from(parent.context),
                    layoutId(),
                    parent,
                    false
            )
    )

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, news: News) {
        (holder as CommonListHolder).binding.setVariable(BR.news, news)
    }

    fun onNewsTagClick(id: String?) {
        //toTagsAct(id)
        id?.let {
            JumpUtil.startActivity(App.getContext(), TagsActivity::class.java, TAG.ACTIVITY_TAGS to it)
        }
    }

    fun onNewsLongClick(imageUrl: String, ancherView: View) {
        ImageUtils.saveImageWithPopup(imageUrl, ancherView)
    }

    fun onNewsClick(id: String, type: String) {
        if (type == "1") JumpUtil.startActivity(App.getContext(), NewsActivity::class.java, "ID" to id, "CODETYPE" to type)
        else JumpUtil.startActivity(App.getContext(), PostActivity::class.java, "ID" to id, "CODETYPE" to type)
    }
}